package com.ronds.webtest.util;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by zhanghui on 2017/2/7.
 * 数据库配置管理
 */
public class ConfigUtil {

    private static Logger logger = Logger.getLogger(ConfigUtil.class);

    static {
        Properties properties = new Properties();
        InputStream inputStream = ConfigUtil.class.getClassLoader().getResourceAsStream("application.properties");
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            logger.error("Couldn't read application.properties file.", e);
        }
        for(Object key : properties.keySet()) {
            CacheUtil.put((String) key, properties.get(key));
        }
    }

    public static String getBaseUrl() {
        return (String) CacheUtil.get("web.baseurl");
    }

    public static String getDbUrl() {
        return (String) CacheUtil.get("database.url");
    }

    public static String getDbUsername() {
        return (String) CacheUtil.get("database.username");
    }

    public static String getDbPassword() {
        return (String) CacheUtil.get("database.password");
    }

}
